/* $RCSFile: RuleEngine.cs $
 * Apache license v2 2011 by Christian Surieux
 * $Source: ?/ADNCRM.RulesEngine/RuleEngine.cs $
 * $log$
 * Revision 6 2010/08/06 19:56:30  christian.surieux
 *   Added Log to All cs files
 */

using System;
using System.Diagnostics;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;
using System.Globalization;

namespace Rewrite.NET
{

    public class EngineConfig : ConfigurationSection
    {
        public static EngineConfig GetConfig()
        {
            return ConfigurationManager.GetSection("Rewrite.NET/Engine") as EngineConfig;
        }

        [ConfigurationProperty("Rules")]
        public RulesCollection Rules
        {
            get
            {
                return this["Rules"] as RulesCollection;
            }
            set
            {
                this["Rules"]   =   value;
            }
        }

        [ConfigurationProperty("breakonfirst",DefaultValue=(bool)true, IsRequired = false)]
        public bool BreakOnFirst
        {
            get
            {
                return (bool)(this["breakonfirst"]);
            }
            set
            {
                this["breakonfirst"] =  value;
            }
        }

        [ConfigurationProperty("AvoidEndUrlList", DefaultValue=".css;.js;.jpg;.gif;.png", IsRequired=false)]
        public string AvoidEndUrlList
        {
            get
            {
                return this["AvoidEndUrlList"] as string;
            }
            set
            {
                this["AvoidEndUrlList"]  =   value;
            }
        }
        [ConfigurationProperty("AvoidAnyUrlList", DefaultValue=".axd;.ashx", IsRequired=false)]
        public string AvoidAnyUrlList
        {
            get
            {
                return this["AvoidAnyUrlList"] as string;
            }
            set
            {
                this["AvoidAnyUrlList"]  =   value;
            }
        }

        [ConfigurationProperty("cacheTimeoutHours", DefaultValue=(int)2, IsRequired=false)]
        [IntegerValidator(MinValue = 0, MaxValue = 100, ExcludeRange = false)]
        public int CacheTimeoutHours
        {
            get
            {
                int ret    =   2;
                object ob   =   this["cacheTimeoutHours"];
                if ( RewriteTraceSwitch.Sw.TraceVerbose )
                    Trace.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]RuleEngine CacheTimeoutHours: '{0}'",ob.ToString()),RewriteTraceSwitch.Sw.Info);
                ret =   (int)ob;
                return ret;
            }
            set
            {
                this["cacheTimeoutHours"] =   value;
            }
        }
        
        [ConfigurationProperty("cacheTimeoutMinutes", DefaultValue=(int)0, IsRequired=false)]
        [IntegerValidator(MinValue = 0, MaxValue = 60, ExcludeRange = false)]
        public int CacheTimeoutMinutes
        {
            get
            {
                return (int)this["cacheTimeoutMinutes"];
            }
            set
            {
                this["cacheTimeoutMinutes"] =   value;
            }
        }
    }
}